s = "3 abc bca cab abc 1"
s=s.split()
print(s)
n = int(s[0])

dic = s[1:-2]
print(dic)
target_word = s[-2]

no = int(s[-1])
dic_bro = []
for i in dic:
    if i != target_word and sorted(i) == sorted(target_word):
        dic_bro.append(i)
dic_bro.sort()
print(len(dic_bro))
if len(dic_bro) >= no:
    print(dic_bro[no - 1])
else:
    pass



